package leetcode.editor.cn;

/**
 * 选择排序
 */
public class ASelectionSort implements AIOrder{
    @Override
    public void sort(int[] nums) {
        for (int i = 0; i < nums.length-1; i++) {
            int minIndex = i;
            for (int j = i+1; j < nums.length; j++) {
                if (nums[j] < nums[minIndex]) {
                    minIndex = j;
                }
            }
            if (minIndex != i) {
                nums[i] ^= nums[minIndex];
                nums[minIndex] ^= nums[i];
                nums[i] ^= nums[minIndex];
            }
        }
    }

    public static void main(String[] args) {
        AIOrder order = new ASelectionSort();
        int[] nums = new int[]{1, 3, 2, 6, 4, 5, 0};
        order.sort(nums);
        System.out.println("end");
    }
}
